Page({
    data: {
        imageUrl: [],
        questionId:0,
    },
    onLoad: function (options) {
        this.setData({
            questionId:options.id
        })
    },
    //提交审核
    submit() {
        if (!this.data.imageUrl) return wx.showToast({
            title: '请上传分享截图',
            icon: 'none'
        })
        wx.$request(wx.$api.mk_up_share_log,{
            question_id:this.data.questionId,
            imgs:this.data.imageUrl.toString()
        }).then(res=>{
            wx.showToast({
                title:'提交成功',
                icon:'none',
                success(res) {
                    setTimeout(()=>{
                        wx.navigateBack();
                    },1000)
                }
            })
        })
    },
    //选取图片
    chooseImage() {
        if (this.data.imageUrl.length >=2){
            wx.showToast({
                title:'最多上传两张截图',
                icon:'none'
            })
            return false
        }
        const _this = this;
        wx.chooseMedia({
            count: 1,
            mediaType: ["image"],
            success: res => {
                console.log(res)
                wx.showLoading({
                    title: '请稍等'
                })
                wx.uploadFile({
                    name: 'file',
                    header: {
                        "Content-Type": "multipart/form-data"
                    },
                    filePath: res.tempFiles[0].tempFilePath,
                    url: wx.$api.upload_img,
                    success(res) {
                        console.log(res);
                        wx.hideLoading();
                        _this.setData({
                            imageUrl: [..._this.data.imageUrl,JSON.parse(res.data).datas.url]
                        })
                    }
                })
            }
        })
    }
});
